﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace FirstGame
{
    public class IntroScreen : GameScreen
    {
        // thời gian xuất hiện của introScreen
        TimeSpan _ScreenTime;

        public TimeSpan ScreenTime
        {
            get { return _ScreenTime; }
            set { _ScreenTime = value; }
        }

        private TimeSpan TempTime = TimeSpan.Zero;

        public IntroScreen(ContentManager content, string background, Vector2 topleft)
        {
            TopLeft = topleft;
            TransitionOnTime = TimeSpan.FromSeconds(1);
            TransitionOffTime = TimeSpan.FromSeconds(1);
            ScreenTime = TimeSpan.FromSeconds(0);
            TransitionPercent = 0.0f;
            ScreenState = ScreenState.TransitionOn;
            Sprites = new List<My2Dsprite>();
            Texture2D[] textures = new Texture2D[1];
            textures[0] = content.Load<Texture2D>(background);
            Sprites = new List<My2Dsprite>();
            My2Dsprite temp = new My2Dsprite(textures, Vector2.Zero);
            temp.Size = new Vector2(800, 480);
            Sprites.Add(temp);
            NSprite = 1;

            _CoverTexture = content.Load<Texture2D>("BackgroundTexture\\nen");
        }

        public override void Update(GameTime gameTime, InputSystem input)
        {
            if (ScreenState == ScreenState.TransitionOn)
            {
                if (!ScreenTransition(gameTime, TransitionOnTime, 1))
                        ScreenState = ScreenState.Active;               
            }
            else if (ScreenState == ScreenState.Active)
            {
                if (ScreenTime == TimeSpan.Zero)
                {
                    ScreenState = ScreenState.TransitionOff;
                }
                else
                {
                    TempTime += gameTime.ElapsedGameTime;
                    if (TempTime >= ScreenTime)
                    {
                        TransitionPercent = 1.0f;
                        ScreenState = ScreenState.TransitionOff;
                    }
                }
            }
            else if (ScreenState == ScreenState.TransitionOff)
            {
                if (!ScreenTransition(gameTime, TransitionOffTime, -1))
                {
                    ScreenState = ScreenState.InActive;
                    Exit();
                }
            }
        }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {          
            Sprites[0].Draw(gameTime, spriteBatch, 255);
            spriteBatch.Draw(_CoverTexture,new Rectangle(0,0,800, 480),new Color(255,255,255,255-ScreenAlpha));
        }

       
    }
}
